package com.zhp.web;

import com.zhp.pojo.HComment;
import com.zhp.pojo.HUserinfo;
import com.zhp.service.CommentService;
import com.zhp.service.UserService;
import com.zhp.service.impl.CommentServiceImpl;
import com.zhp.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @date 2023/4/12
 * @desc
 */
@WebServlet("/showXq")
public class ShowXqServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String did = req.getParameter("did");

        UserService userService = new UserServiceImpl();

        HUserinfo userinfo = userService.findUserInfoById(Integer.parseInt(did));

        System.out.println("-=== "+userinfo);

        HttpSession session = req.getSession();
        session.setAttribute("doc",userinfo);
//        req.setAttribute("doc",userinfo);

        //准备评论数据
        CommentService commentService = new CommentServiceImpl();

        List<HComment> comments = commentService.findCommentByDid(did);

        req.setAttribute("cs",comments);
        req.getRequestDispatcher("/xq.jsp").forward(req,resp);
    }
}
